package vip.xiaoh.consumer.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import vip.xiaoh.consumer.service.IRemoteClient;

@Slf4j
@RestController
public class DemoController {

    private final RestTemplate restTemplate;

    @Autowired
    private IRemoteClient remoteClient;

    @Autowired
    public DemoController(RestTemplate restTemplate) {this.restTemplate = restTemplate;}

    /**
     * 调用方法一
     * @param str
     * @return
     */
    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
    }

    /**
     * 调用方法二
     * @return
     */
    @RequestMapping(value = "/helloNacos", method = RequestMethod.GET)
    public String helloNacos() {
        return remoteClient.helloNacos();
    }

}
